﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>添加 到货通知单</title>
    <link href="//unpkg.com/layui@2.9.21-rc.3/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <h2>添加到货通知单</h2>
    <br />
    <br />
    <form>
        <!-- 通知单编号 -->
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span><b>通知单编号</b></label>
            <div class="layui-input-inline">
                <input style="width:190px" type="text" id="arrivalNoticeNode" name="arrivalNoticeNode" lay-verify="required" placeholder="请输入通知单编号" autocomplete="off" class="layui-input">
                <div class="layui-input-suffix">
                    <div class="layui-input-inline">
                        <div class="layui-input-group">
                            <button style="left:30px" type="button" class="layui-btn layui-btn-primary layui-btn-xs" onclick="arrivalAlls()">自动生成</button>
                        </div>
                    </div>
                </div>
        </div>

        <!-- 通知单名称 -->
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span><b>通知单名称</b></label>
            <div class="layui-input-inline" style="width:500px">
                <input type="text" id="arrivalNoticeName" name="arrivalNoticeName" lay-verify="required" placeholder="请输入通知单名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 采购订单编号 -->
        <div class="layui-form-item">
            <label class="layui-form-label"><b>采购订单编号</b></label>
            <div class="layui-input-inline" style="width:500px">
                <input type="text" id="purchaseIndentId" name="purchaseIndentId" lay-verify="required" placeholder="请输入采购订单编号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 供应商 -->
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span><b>供应商</b></label>
            <div class="layui-input-group">
                    <input type="text" id="supplierName" name="supplierName" placeholder="请选择供应商" class="layui-input">
                <div class="layui-input-split layui-input-suffix" style="cursor: pointer;">
                    <i class="layui-icon layui-icon-search" lay-on="test-page"></i>
                </div>
            </div>
        </div>

        <!-- 到货日期 -->
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color:red">*</span><b>到货日期</b></label>
            <div class="layui-input-inline">
                @* <input type="text" name="pickingTime" class="layui-input" id="ID-laydate-type-datetime"  > *@
                <input type="text" name="arrivalNoticeTime" id="ID-laydate-type-datetime" lay-verify="date" placeholder="请选择到货日期" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 联系人 -->
        <div class="layui-form-item">
            <label class="layui-form-label"><b>联系人</b></label>
            <div class="layui-input-inline" style="width:500px">
                <input type="text" id="phoneName" name="phoneName" lay-verify="required" placeholder="请输入联系人" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 联系方式 -->
        <div class="layui-form-item">
            <label class="layui-form-label"><b>联系方式</b></label>
            <div class="layui-input-inline" style="width:500px">
                <input type="text" id="phone" name="phone" lay-verify="required" placeholder="请输入联系方式" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!-- 备注 -->
        <div class="layui-form-item">
            <label style="right:10px" class="layui-form-label"><b>备注</b></label>
            <div class="layui-input-inline" style="width:600px">
                <textarea name="remark" id="remark" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>

        <!-- 按钮 -->
        <div class="layui-form-item" style="left:570px">
            <div class="layui-btn-container">
                <button type="button" class="layui-btn layui-bg-blue" lay-submit lay-filter="demo1">保存</button>
                <button type="button" class="layui-btn ">取消</button>
            </div>
        </div>
    </form>

    <!-- HTML Content -->
    <script src="//unpkg.com/layui@2.9.21-rc.3/dist/layui.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        layui.use(['form', 'laydate', 'util'], function () {
            var $ = layui.$;
            var form = layui.form;
            var layer = layui.layer;
            var laypage = layui.laypage;
            var laydate = layui.laydate;
            var table = layui.table;
            var util = layui.util;

            //供应商
            util.on('lay-on', {
                'test-page': function(){
                   layer.open({
                    type: 1,
                    area: '100%',
                    resize: false,
                    shadeClose: true,
                    title: '供应商选择',
                    content:`
                             <form class="layui-form" action="">
                <div class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-input-group">
                            <div class="layui-input-prefix">
                                供应商编码
                            </div>
                            <div>
                                <input id="supplierNo" type="text" placeholder="请输入供应商编码" class="layui-input">
                            </div>

                            <div class="layui-input-prefix" style="left:50px">
                                供应商名称
                            </div>
                            <div style="left:50px">
                                <input id="supplierName" type="text" placeholder="请输入供应商名称" class="layui-input">
                            </div>

                            <div class="layui-input-prefix" style="left:100px">
                                供应商简称
                            </div>
                            <div style="left:100px">
                                <input id="supplierShort" type="text" placeholder="请输入供应商简称" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-group">
                            <div class="layui-input-prefix" style="left:14px">
                                英文名称
                            </div>
                            <dic style="left:14px">
                                <input id="supplierEnglishName" type="text" placeholder="请输入供应商英文名称" class="layui-input">
                            </dic>

                            <div class="layui-input-prefix" style="left:77px">
                                是否启用
                            </div>
                            <div style="left:77px;width:197px">
                                <select id="supplierIsNo" lay-filter="testSelect">
                                    <option value="-1">是否启用</option>
                                    <option value="0">禁用</option>
                                    <option value="1">启用</option>
                                </select>
                            </div>

                            <div style="left:150px">
                                <button onclick="ShowSupplier()" id="searchBtn" type="button" class="layui-btn layui-btn-normal">搜索</button>

                            </div>

                            <div style="left:170px">
                                <button onclick="Break()" type="button" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-input-group">
                            <div>
                                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary layui-border-blue" lay-on="test-page-custom">
                                    <i class="layui-icon layui-icon-add-1">新增</i>
                                </button>
                            </div>
                        </div>
                    </div>

                    <table style="left:320px" class="layui-table">
                        <thead>
                            <tr>
                                <td><input type="checkbox" name="check" onclick="checkAll()" /></td>
                                <td>供应商编码</td>
                                <td>供应商名称</td>
                                <td>供应商简称</td>
                                <td>供应商等级</td>
                                <td>供应商评分</td>
                                <td>供应商电话</td>
                                <td>是否启用</td>
                                <td>备注</td>
                                <td>操作</td>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                    <div id="demo-laypage-all"></div>
                </div>
            </form>
                    `,
                    //success
                      success: function () {
                            var pageIndex = 1;
                            var pageSize = 2;

                            $(function () {
                                ShowSupplier(pageIndex, pageSize);
                            })
                            // 获取供应商编码
                            $('#searchBtn').click(function () {
                                var supplier = $('#supplierNo').val();
                                ShowSupplier(pageIndex, pageSize)
                            });
                            // 获取供应商名称
                            $('#searchBtn').click(function () {
                                var supplier1 = $('#supplierName').val();
                                ShowSupplier(pageIndex, pageSize)
                            });
                            //供应商简称
                            $('#searchBtn').click(function () {
                                var supplier2 = $('#supplierShort').val();
                                ShowSupplier(pageIndex, pageSize)
                            });
                            // 英文名称
                            $('#searchBtn').click(function () {
                                var supplier2 = $('#supplierEnglishName').val();
                                ShowSupplier(pageIndex, pageSize)
                            });
                            //是否启用
                            form.on('select(testSelect)', function (data) {
                                ShowPermission(data.value); // data.value
                            });
                            //供应商管理列表
                            function ShowSupplier(index, size) {
                                var supplierNo = $("#supplierNo").val() || "";
                                var supplierName = $("#supplierName").val() || "";
                                var supplierShort = $("#supplierShort").val() || "";
                                var supplierEnglishName = $("#supplierEnglishName").val() || "";
                                var supplierIsNo = $("#supplierIsNo").val() || -1;
                                $.ajax({
                                    url: '@ViewBag.FoundationRead' + "/api/UserLi/SearchSupplier",
                                    data: JSON.stringify({ supplierNo: supplierNo, supplierName: supplierName, supplierShort: supplierShort, supplierEnglishName: supplierEnglishName, supplierIsNo: supplierIsNo, pageIndex: index, pageSize: size }),
                                    type: "post",
                                    async: false,
                                    dataType: "json",
                                    contentType: "application/json",
                                    success: res => {
                                        var tbody = $("tbody");
                                        tbody.empty();
                                        if (res.data != null) {
                                            $.each(res.data, function () {
                                                tbody.append(`
                                                    <tr>
                                                        <td><input type="checkbox" class="check" value="${this.supplierId}" onclick="checkfan()" /></td>
                                                        <td>${this.supplierNo}</td>
                                                        <td>${this.supplierName}</td>
                                                        <td>${this.supplierShort}</td>
                                                        <td>${this.supplierClassName}</td>
                                                        <td>${this.supplieScore}</td>
                                                        <td>${this.supplierPhone}</td>
                                                        <td>${this.supplierIsNo === 1 ? '启用' : '禁用'}</td>
                                                        <td>${this.supplierRemark}</td>
                                                        <td><a onclick="Dass('${this.supplierName}')" class="btn btn-link">选择</a></td>
                                                    </tr>`);
                                            });
                                        }
                                        form.render(); // 重新渲染下拉框
                                        //完整显示
                                        laypage.render({
                                            elem: 'demo-laypage-all', // 元素 id
                                            count: res.totalCount, // 数据总数
                                            curr: index,//当前页
                                            limit: size,//每页几条
                                            limits: [2, 3, 4],
                                            layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'], // 功能布局
                                            jump: function (obj, first) {
                                                if (!first) {
                                                    ShowSupplier(obj.curr, obj.limit);
                                                }
                                            }
                                        });
                                    }
                                })
                            }

                            // 对弹层中的表单进行初始化渲染
                            form.render();
                            // 表单提交事件
                            form.on('submit(demo-Search)', function (data) {
                                var field = data.field; // 获取表单字段值

                                // 显示填写结果，仅作演示用
                                // layer.alert(JSON.stringify(field), {
                                //     title: '当前填写的字段值'
                                // });
                                // 此处可执行 Ajax 等操作
                                // …

                                return false; // 阻止默认 form 跳转
                            });

                     }
                   })
                }
            })

            // 日期时间选择器
            laydate.render({
                elem: '#ID-laydate-type-datetime'
            });

            //到货通知 新增
            form.on('submit(demo1)', function (data) {
                //定义变量
                var datas = {
                    arrivalNoticeNode: $("[name='arrivalNoticeNode']").val(), //通知单编号
                    arrivalNoticeName: $("[name='arrivalNoticeName']").val(), //通知单名称
                    purchaseIndentId: $("[name=purchaseIndentId]").val(), //采购订单编号
                    arrivalNoticeTime: $("[name=arrivalNoticeTime]").val(), //到货日期
                    phoneName: $("[name=phoneName]").val(), //联系人
                    phone: $("[name=phone]").val(), //联系方式
                    remark: $("[name=remark]").val(), //备注        
                    supplierName: $("[name=supplierName]").val(), //供应商名称
                    documents: 1, //单据状态
                };
                console.log(datas);

                $.ajax({
                    url: '@ViewBag.FoundationWrite' + '/api/ProductType/ArrivalNoticesAdds',
                    data: JSON.stringify(datas),
                    type: "post",
                    dataType: "json",
                    contentType: "application/json",
                    success: function (res) {
                        console.log(123, res);
                        if (res.code > 0) {
                            layer.alert('保存成功!');
                            location.href = "/Messages/ArrivalNoticesList";
                        }
                        else {
                            alert('保存失败!')
                        }
                    }
                })
                // layer.alert(JSON.stringify(field), {
                //     title: '当前填写的字段值'
                // });
                // 此处可执行 Ajax 等操作
                return false; // 阻止默认 form 跳转
            })
            //////////////////////////////////////
        });

        //自动生成 通知单编号     
        function arrivalAlls() {
            var datec = new Date();
            var year = datec.getFullYear();
            var month = (datec.getMonth() + 1).toString().padStart(2, "0");
            var date = (datec.getDate() + 1).toString().padStart(2, "0");
            var hours = datec.getHours();
            var minute = (datec.getMinutes()).toString().padStart(2, "0");
            var seconds = (datec.getSeconds()).toString().padStart(2, "0");
            // var Encoding = "IF";
            var result = "AN" + year + month + date + hours + minute + seconds;
            console.log(result);
            $("#arrivalNoticeNode").val(result);
        };
        // 这里的代码可以使用$符号，因为jQuery已经加载完成
        // $(document).ready(function () {
        //     // 你的jQuery代码
        // });

        //反填 供应商
        function Dass(nameMC) {
            console.log(nameMC)
            $("[name='supplierName']").val(nameMC);
            layer.close(layer.index); // 关闭弹层
            // form.render(); // 重新渲染
        }
    </script>
</body>
</html>